import datetime

class BinBackTrade:

    @staticmethod
    def generate_dates_and_times(start, end):
        """
        生成 时间索引
        :param start: 起始日期
        :param end: 结束日期
        :return: None
        """
        if isinstance(start, str):
            start_date = datetime.datetime.strptime(start, '%Y-%m-%d').date()
        if isinstance(end, str):
            end_date = datetime.datetime.strptime(end, '%Y-%m-%d').date()

        # 初始化结果列表
        result = []

        # 计算日期范围
        delta = end- start
        for i in range(delta.days + 1):
            current_date = start + datetime.timedelta(days=i)

            # 创建早上9:30的datetime
            morning_time = datetime.datetime.combine(current_date, datetime.time(9, 30))

            # 创建下午3:00的datetime
            afternoon_time = datetime.datetime.combine(current_date, datetime.time(15, 0))

            # 添加到结果列表
            result.append({
                'date': current_date,
                'open': morning_time,
                'close': afternoon_time
            })
        return result

    @classmethod
    def initial(cls):

        begin = cls.begin
        end =  cls.end
        data = cls.data
        cls.timeIndexMethod = cls.generate_dates_and_times(begin, end)

    def __init__(self,data,begin,end):

        self.data = data
        self.begin = begin
        self.end = end



